<template>
	<view>
		<view class="bg-white padding-xl">
			<view>{{type=='performance'?'转入':'充值'}}金额</view>
			<input class="ipt" v-model="form.amount" type="number">

			<view v-show="type=='performance'">
				<view>{{performance}}</view>
				<view class="text-blue" @click="form.amount=performance">全部转入</view>
			</view>

			<u-gap height="40" v-show="type!='performance'"></u-gap>

			<view class="quick" v-show="type!='performance'">
				<view class="box" v-for="i in quick" :key="i" @click="form.amount=i">
					{{i}}元
				</view>
			</view>
		</view>

		<my-btn gold size="sm" style="margin: 60rpx auto;" @click="submit">{{type=='performance'?'转入':'充值'}}</my-btn>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: '',
				performance: '',
				quick: [50, 100, 200, 300, 500, 1000, 2000, 3000, 5000],
				form: {
					amount: 100
				}
			};
		},
		onLoad(opt) {
			this.type = opt.type || ''
			this.getJixiao()
		},
		methods: {
			submit() {
				uni.showLoading({
					title: '请稍等...',
					mask: true
				})
				if (this.type == 'performance') {
					this.jixiao()
				} else {
					this.yue()
				}
			},
			yue() {
				this.$u.post('/finance/balance/recharge', this.form).then(res => {
					let no = res.data.result.trade_no
					uni.hideLoading()
					if (res.data.code==0) {
						this.$goto('/pages/order/pay-yue?no=' + no)
					} else {
						this.$msg(res.data.msg)
					}
				})
			},
			jixiao() {
				this.$u.post('/finance/transfer/performance/balance', this.form).then(res => {
					uni.hideLoading()
					this.$msg(res.data.msg)
					this.getJixiao()
				})
			},
			getJixiao() {
				this.$u.get('/finance/balance').then(res => {
					this.performance = res.data.result.finance.performance
				})
			}
		}
	}
</script>

<style lang="scss">
	.ipt {
		margin: 40rpx 0;
		width: 400rpx;
		height: 80rpx;
		padding: 0 16rpx;
		font-size: 48rpx;
		background: rgba(245, 245, 245, 1);
		border-radius: 4rpx;
		border: 2rpx solid rgba(153, 153, 153, 1);
	}

	.quick {
		height: 380rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		align-items: space-around;

		.box {
			width: 200rpx;
			height: 100rpx;
			border-radius: 8rpx;
			border: 2rpx solid rgba(153, 153, 153, 1);
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
</style>
